package o;

import android.util.Log;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import java.util.HashMap;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;

public final class uf implements ud {
    private int ʻ;
    private final ui<d, Object> ˊ;
    private final Map<Class<?>, NavigableMap<Integer, Integer>> ˋ;
    private final int ˎ;
    private final a ˏ;
    private final Map<Class<?>, ub<?>> ॱ;

    static final class a extends tz<d> {
        protected /* synthetic */ ul ˏ() {
            return ˎ();
        }

        a() {
        }

        d ˋ(int i, Class<?> cls) {
            d dVar = (d) ˋ();
            dVar.ˏ(i, cls);
            return dVar;
        }

        protected d ˎ() {
            return new d(this);
        }
    }

    static final class d implements ul {
        private final a ˋ;
        private Class<?> ˎ;
        int ॱ;

        d(a aVar) {
            this.ˋ = aVar;
        }

        void ˏ(int i, Class<?> cls) {
            this.ॱ = i;
            this.ˎ = cls;
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof d)) {
                return false;
            }
            d dVar = (d) obj;
            if (this.ॱ == dVar.ॱ && this.ˎ == dVar.ˎ) {
                return true;
            }
            return false;
        }

        public String toString() {
            return "Key{size=" + this.ॱ + "array=" + this.ˎ + '}';
        }

        public void ˎ() {
            this.ˋ.ॱ(this);
        }

        public int hashCode() {
            return (this.ˎ != null ? this.ˎ.hashCode() : 0) + (this.ॱ * 31);
        }
    }

    @VisibleForTesting
    public uf() {
        this.ˊ = new ui();
        this.ˏ = new a();
        this.ˋ = new HashMap();
        this.ॱ = new HashMap();
        this.ˎ = 4194304;
    }

    public uf(int i) {
        this.ˊ = new ui();
        this.ˏ = new a();
        this.ˋ = new HashMap();
        this.ॱ = new HashMap();
        this.ˎ = i;
    }

    public synchronized <T> void ˊ(T t) {
        Class cls = t.getClass();
        ub ˎ = ˎ(cls);
        int ॱ = ˎ.ॱ(t);
        int ˎ2 = ˎ.ˎ() * ॱ;
        if (ˎ(ˎ2)) {
            d ˋ = this.ˏ.ˋ(ॱ, cls);
            this.ˊ.ˋ(ˋ, t);
            NavigableMap ˊ = ˊ(cls);
            Integer num = (Integer) ˊ.get(Integer.valueOf(ˋ.ॱ));
            ˊ.put(Integer.valueOf(ˋ.ॱ), Integer.valueOf(num == null ? 1 : num.intValue() + 1));
            this.ʻ += ˎ2;
            ˊ();
        }
    }

    public synchronized <T> T ˊ(int i, Class<T> cls) {
        return ˎ(this.ˏ.ˋ(i, cls), cls);
    }

    public synchronized <T> T ॱ(int i, Class<T> cls) {
        d ˋ;
        Integer num = (Integer) ˊ((Class) cls).ceilingKey(Integer.valueOf(i));
        if (ˏ(i, num)) {
            ˋ = this.ˏ.ˋ(num.intValue(), cls);
        } else {
            ˋ = this.ˏ.ˋ(i, cls);
        }
        return ˎ(ˋ, cls);
    }

    private <T> T ˎ(d dVar, Class<T> cls) {
        ub ˎ = ˎ((Class) cls);
        T ˊ = ˊ(dVar);
        if (ˊ != null) {
            this.ʻ -= ˎ.ॱ(ˊ) * ˎ.ˎ();
            ˋ(ˎ.ॱ(ˊ), cls);
        }
        if (ˊ != null) {
            return ˊ;
        }
        if (Log.isLoggable(ˎ.ॱ(), 2)) {
            Log.v(ˎ.ॱ(), "Allocated " + dVar.ॱ + " bytes");
        }
        return ˎ.ˋ(dVar.ॱ);
    }

    @Nullable
    private <T> T ˊ(d dVar) {
        return this.ˊ.ˋ((ul) dVar);
    }

    private boolean ˎ(int i) {
        return i <= this.ˎ / 2;
    }

    private boolean ˏ(int i, Integer num) {
        return num != null && (ˏ() || num.intValue() <= i * 8);
    }

    private boolean ˏ() {
        return this.ʻ == 0 || this.ˎ / this.ʻ >= 2;
    }

    public synchronized void ˋ() {
        ˊ(0);
    }

    public synchronized void ॱ(int i) {
        if (i >= 40) {
            ˋ();
        } else if (i >= 20 || i == 15) {
            ˊ(this.ˎ / 2);
        }
    }

    private void ˊ() {
        ˊ(this.ˎ);
    }

    private void ˊ(int i) {
        while (this.ʻ > i) {
            Object ˋ = this.ˊ.ˋ();
            aas.ˎ(ˋ);
            ub ˎ = ˎ(ˋ);
            this.ʻ -= ˎ.ॱ(ˋ) * ˎ.ˎ();
            ˋ(ˎ.ॱ(ˋ), ˋ.getClass());
            if (Log.isLoggable(ˎ.ॱ(), 2)) {
                Log.v(ˎ.ॱ(), "evicted: " + ˎ.ॱ(ˋ));
            }
        }
    }

    private void ˋ(int i, Class<?> cls) {
        NavigableMap ˊ = ˊ((Class) cls);
        Integer num = (Integer) ˊ.get(Integer.valueOf(i));
        if (num == null) {
            throw new NullPointerException("Tried to decrement empty size, size: " + i + ", this: " + this);
        } else if (num.intValue() == 1) {
            ˊ.remove(Integer.valueOf(i));
        } else {
            ˊ.put(Integer.valueOf(i), Integer.valueOf(num.intValue() - 1));
        }
    }

    private NavigableMap<Integer, Integer> ˊ(Class<?> cls) {
        NavigableMap<Integer, Integer> navigableMap = (NavigableMap) this.ˋ.get(cls);
        if (navigableMap != null) {
            return navigableMap;
        }
        NavigableMap treeMap = new TreeMap();
        this.ˋ.put(cls, treeMap);
        return treeMap;
    }

    private <T> ub<T> ˎ(T t) {
        return ˎ(t.getClass());
    }

    private <T> ub<T> ˎ(Class<T> cls) {
        ub<T> ubVar = (ub) this.ॱ.get(cls);
        if (ubVar == null) {
            if (cls.equals(int[].class)) {
                ubVar = new ue();
            } else if (cls.equals(byte[].class)) {
                ubVar = new uh();
            } else {
                throw new IllegalArgumentException("No array pool found for: " + cls.getSimpleName());
            }
            this.ॱ.put(cls, ubVar);
        }
        return ubVar;
    }
}
